//
//  UIImage+Extension.swift
//  weibo002
//
//  Created by 黑眼圈 on 16/4/26.
//  Copyright © 2016年 heiyan. All rights reserved.
//

import UIKit


extension UIImage {
    
    
    //压缩图片
    func compressImg(w:Int)->UIImage{
        
        
        let h = CGFloat(w)/self.size.width*self.size.height
        
        let rect = CGRect(x: 0, y: 0, width: w, height: Int(h))
        
        
        // 开启图形上下文对象
        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0.0)
        
        //画图
        self.drawInRect(rect)
        
        //从图形上下文中获取图片
        let img = UIGraphicsGetImageFromCurrentImageContext()
        
        //关闭图形上下文对象
        UIGraphicsEndImageContext()
        
        
        return img
        
    }
    
    
    
}
